package org.boulderfoodrescue.webapp.client.events;

import org.boulderfoodrescue.webapp.shared.Location;
import org.boulderfoodrescue.webapp.shared.Location.LocationType;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.shared.GwtEvent;

public class DonorInfoUpdatedEvent extends GwtEvent<DonorInfoUpdatedHandler>{
  private static final Type<DonorInfoUpdatedHandler> TYPE = new Type<DonorInfoUpdatedHandler>();
  private ChangeType changeType;
  private Location location;
  
  public DonorInfoUpdatedEvent(ChangeType changeType, Location location) {
    if(location.getType() != LocationType.Donor)
    {
      Log.error("Epected a location of type donor.");
      return;
    }
    this.changeType = changeType;
    this.location = location;
  }

  public static Type<DonorInfoUpdatedHandler> getType() {
    return TYPE;
  }

  @Override
  public com.google.gwt.event.shared.GwtEvent.Type<DonorInfoUpdatedHandler> getAssociatedType() {
    return TYPE;
  }
  
  @Override
  protected void dispatch(DonorInfoUpdatedHandler handler) {
    switch(changeType)
    {
    case Added: handler.onDonorAdded(this);break;
    case Removed: handler.onDonorRemoved(this);break;
    case Updated: handler.onDonorUpdated(this);break;
    }
  }

  public Location getValue(){
    return location;
  }
}
